import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import tensorflow.examples.tutorials.mnist.input_data as input_data
mnist=input_data.read_data_sets('MINST_data/',one_hot=True)
# print('验证集',mnist.validation.images.shape,
#       '测试集',mnist.validation.labels.shape)
# def plot_image(image):
#     plt.imshow(image.reshape(28,28),cmap='binary')
#     plt.show()
# plot_image(mnist.train.images[1])
# plot_image(mnist.train.images[555])
# print(mnist.train.labels[0:20])
batch_images_xs,batch_labels_ys=mnist.train.next_batch(batch_size=10)

x=tf.placeholder(tf.float32,[None,784],name="X")
y=tf.placeholder(tf.float32,[None,10],name='Y')

W=tf.Variable(tf.random_normal([784,10]),name="W")
b=tf.Variable(tf.zeros([10]),name="b")

norm=tf.random_normal([100])
with tf.Session() as sess:
    norm_data=norm.eval()
forward=tf.matmul(x,W)+b
# 数值


pred=tf.nn.softmax(forward)
#训练参数
train_epochs=50
batch_size=100
total_batch=int(mnist.train.num_examples/batch_size)
display_step=1
learning_rate=0.01

loss_function=tf.reduce_mean(-tf.reduce_sum(y*tf.log(pred),reduction_indices=1))
optimizer=tf.train.GradientDescentOptimizer(learning_rate).minimize((loss_function))
#检查预测类别tf.argmax(pred,1)与实际类别tf.argmax(y，1）的匹配情况
correct_prediction=tf.equal(tf.argmax(pred,1),tf.argmax(y,1))
#准确率，将布尔值转化为浮点数，并计算平均值
accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
sess=tf.Session()
init=tf.global_variables_initializer()
sess.run(init)


